package com.biz.primus.model.promotion.vo.req;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 订单促销请求Vo Item
 *
 * @author david-liu
 */
@Getter
@Setter
@ApiModel(value = "订单促销信息商品项明细")
public class OrderPromotionReqItemVo implements IProductPromotionReqVo, Serializable {
    private static final long serialVersionUID = -6131528882831427657L;

    /**
     * 商品ID
     */
    @ApiModelProperty(value = "商品ID", required = true)
    private Long productId;

    /**
     * 商品数量
     */
    @ApiModelProperty(value = "商品数量", required = true)
    private Integer quantity;

    /**
     * 商品分类ID
     */
    @ApiModelProperty(value = "商品分类ID", required = true)
    private Long categoryId;

    /**
     * 商品品牌ID
     */
    @ApiModelProperty(value = "商品品牌ID", required = true)
    private Long brandId;

    /**
     * 商品价格
     */
    @ApiModelProperty(value = "商品价格", required = true)
    private Integer originPrice;

    @ApiModelProperty(value = "商品特价", required = true)
    private Integer specialOfferPrice;

    @ApiModelProperty(value = "商品最多以特价购买的数量", required = true)
    private Integer specialOfferQuantityLimit;

    /**
     * 获取商品总价
     *
     * @return 商品总价
     */
    public Integer getProductAmount() {
        if (Objects.isNull(specialOfferPrice)) {
            return this.originPrice * this.getQuantity();
        }
        if (Objects.isNull(this.specialOfferQuantityLimit)) {
            return this.specialOfferPrice * this.getQuantity();
        }
        if (this.getQuantity() <= this.specialOfferQuantityLimit) {
            return this.specialOfferPrice * this.getQuantity();
        }
        return (this.specialOfferPrice * this.specialOfferQuantityLimit) + this.originPrice * (this.getQuantity() - this.specialOfferQuantityLimit);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
    }
}
